import time

from selenium import webdriver
from selenium.webdriver import ActionChains, Keys
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait

# 1.创建驱动对象
service = Service("C:/Program Files/Google/Chrome/Application/chromedriver.exe")
driver = webdriver.Chrome(service=service)

# 2.打开浏览器
driver.get("file:///C:/Users/82073/Desktop/pagetest/%E6%B3%A8%E5%86%8CA.html")

# 显式等待
wait = WebDriverWait(driver, 10, 1)
ele = wait.until(lambda x: x.find_element(By.CSS_SELECTOR, "input[placeholder='延时加载的输入框']"))
ele.send_keys("admin")

# 隐式等待, 最长等待时间设置为10s
# 注: 如果找到元素, 不会等待到10s, 直接获取, 是很灵活的
# driver.implicitly_wait(10)
# driver.find_element(By.CSS_SELECTOR, "input[placeholder='延时加载的输入框']").send_keys("admin")

# 4.3s后关闭
time.sleep(3)

# 5.关闭驱动对象
driver.close()